import { request } from '@pkg/request/src';

export enum Api {
  list = '/role/page',
  save = '/role/add',
  edit = '/role/update',
  remove = '/role/remove',
  authorityMenu = '/authority/menu',
  authorityRole = 'authority/role',
  setUser = '/role/users/add',
  organizationList = '/system/organization/list',
  userGrant = '/authority/user/grant',
  roleGrant = '/authority/role/grant',
  addAction= '/action/add',

  airportList = '/airport/list',
  querySetAirport = '/roleAirport/querySetAirport',
  setAirport = '/roleAirport/setAirport',
}

/**
 * 保存用户角色
 * @param params
 * @param isUpdate
 */
export const saveOrUpdateUser = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return request.post({ url: url, params });
};
/**
 * 保存按钮
 * @param isUpdate
 */
export const saveAction = (params) => {
  return request.post({url: Api.addAction , params});
};

/**
 * 加载可授权角色和已授权角色
 * @param params
 */
export const listByType = (roleType) => {
  return `role/listByType/${roleType}`;
};

/**
 * 获取角色已分配权限
 * @param roleId
 */
export const getAuthorityRole = (roleId) => {
  const params = {
    roleId: roleId,
  };
  return request.get({ url: Api.authorityRole, params });
};

/**
 * 获取菜单和操作权限列表
 * @param params
 */
export const getAuthorityMenu = () => {
  return request.get({ url: Api.authorityMenu });
};

/**
 * 提交角色授权
 * @param params
 */
export const setRoleGrant = (params) => {
  return request.post({ url: Api.roleGrant, params });
};
/**
 * 获取机构
 */
export const getOrganizationList = (params) => request.get({ url: Api.organizationList, params });

/**
 * 查询全部机场
 * @param params
 */
export const airportList = (params) => {
  return request.get({ url: Api.airportList, params });
};
/**
 * 查询角色已设置机场
 * @param params
 */
export const querySetAirport = (params) => {
  return request.get({ url: Api.querySetAirport, params });
};
/**
 * 查询角色已设置机场
 * @param params
 */
export const setAirport = (params) => {
  return request.post({ url: Api.setAirport, params });
};
